#include "widget.h"
#include "ui_widget.h"

#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

// 修改QRect对象的x和y，使QRect的高度宽度发生变化
//void Widget::on_pushButton_up_clicked()
//{
//    // 获取到target本身的geometry
//    QRect rect = ui->pushButton_target->geometry();
//    qDebug() << rect;

//    rect.setY(rect.y() - 5);
//    ui->pushButton_target->setGeometry(rect);
//}

//void Widget::on_pushButton_down_clicked()
//{
//    // 获取到target本身的geometry
//    QRect rect = ui->pushButton_target->geometry();
//    qDebug() << rect;

//    rect.setY(rect.y() + 5);
//    ui->pushButton_target->setGeometry(rect);
//}

//void Widget::on_pushButton_left_clicked()
//{
//    // 获取到target本身的geometry
//    QRect rect = ui->pushButton_target->geometry();
//    qDebug() << rect;

//    rect.setX(rect.x() - 5);
//    ui->pushButton_target->setGeometry(rect);
//}

//void Widget::on_pushButton_right_clicked()
//{
//    // 获取到target本身的geometry
//    QRect rect = ui->pushButton_target->geometry();
//    qDebug() << rect;

//    rect.setX(rect.x() + 5);
//    ui->pushButton_target->setGeometry(rect);
//}

// 平移target
void Widget::on_pushButton_up_clicked()
{
    // 获取到target本身的geometry
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << rect;
//    rect.setY(rect.y() - 5);
//    ui->pushButton_target->setGeometry(rect);
    ui->pushButton_target->setGeometry(rect.x(), rect.y()-5, rect.width(), rect.height());

}

void Widget::on_pushButton_down_clicked()
{
    // 获取到target本身的geometry
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << rect;
//    rect.setY(rect.y() + 5);
//    ui->pushButton_target->setGeometry(rect);
    ui->pushButton_target->setGeometry(rect.x(), rect.y() + 5, rect.width(), rect.height());

}

void Widget::on_pushButton_left_clicked()
{
    // 获取到target本身的geometry
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << rect;
//    rect.setX(rect.x() - 5);
//    ui->pushButton_target->setGeometry(rect);
    ui->pushButton_target->setGeometry(rect.x() - 5, rect.y(), rect.width(), rect.height());

}

void Widget::on_pushButton_right_clicked()
{
    // 获取到target本身的geometry
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << rect;
//    rect.setX(rect.x() + 5);
//    ui->pushButton_target->setGeometry(rect);
    ui->pushButton_target->setGeometry(rect.x() + 5, rect.y(), rect.width(), rect.height());

}
